/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class CandidatoDAOImpl implements orm.dao.CandidatoDAO {
	public Candidato loadCandidatoByORMID(int id) throws PersistentException {
		try {
			PersistentSession session = orm.VotoElectronicoPersistentManager.instance().getSession();
			return loadCandidatoByORMID(session, id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Candidato getCandidatoByORMID(int id) throws PersistentException {
		try {
			PersistentSession session = orm.VotoElectronicoPersistentManager.instance().getSession();
			return getCandidatoByORMID(session, id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Candidato loadCandidatoByORMID(int id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.VotoElectronicoPersistentManager.instance().getSession();
			return loadCandidatoByORMID(session, id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Candidato getCandidatoByORMID(int id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.VotoElectronicoPersistentManager.instance().getSession();
			return getCandidatoByORMID(session, id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Candidato loadCandidatoByORMID(PersistentSession session, int id) throws PersistentException {
		try {
			return (Candidato) session.load(orm.Candidato.class, new Integer(id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Candidato getCandidatoByORMID(PersistentSession session, int id) throws PersistentException {
		try {
			return (Candidato) session.get(orm.Candidato.class, new Integer(id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Candidato loadCandidatoByORMID(PersistentSession session, int id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Candidato) session.load(orm.Candidato.class, new Integer(id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Candidato getCandidatoByORMID(PersistentSession session, int id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Candidato) session.get(orm.Candidato.class, new Integer(id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Candidato[] listCandidatoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.VotoElectronicoPersistentManager.instance().getSession();
			return listCandidatoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Candidato[] listCandidatoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.VotoElectronicoPersistentManager.instance().getSession();
			return listCandidatoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Candidato[] listCandidatoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Candidato as Candidato");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Candidato[]) list.toArray(new Candidato[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Candidato[] listCandidatoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Candidato as Candidato");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Candidato[]) list.toArray(new Candidato[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Candidato loadCandidatoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.VotoElectronicoPersistentManager.instance().getSession();
			return loadCandidatoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Candidato loadCandidatoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.VotoElectronicoPersistentManager.instance().getSession();
			return loadCandidatoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Candidato loadCandidatoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Candidato[] candidatos = listCandidatoByQuery(session, condition, orderBy);
		if (candidatos != null && candidatos.length > 0)
			return candidatos[0];
		else
			return null;
	}
	
	public Candidato loadCandidatoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Candidato[] candidatos = listCandidatoByQuery(session, condition, orderBy, lockMode);
		if (candidatos != null && candidatos.length > 0)
			return candidatos[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateCandidatoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.VotoElectronicoPersistentManager.instance().getSession();
			return iterateCandidatoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateCandidatoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.VotoElectronicoPersistentManager.instance().getSession();
			return iterateCandidatoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateCandidatoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Candidato as Candidato");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateCandidatoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Candidato as Candidato");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Candidato createCandidato() {
		return new orm.Candidato();
	}
	
	public boolean save(orm.Candidato candidato) throws PersistentException {
		try {
			orm.VotoElectronicoPersistentManager.instance().saveObject(candidato);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Candidato candidato) throws PersistentException {
		try {
			orm.VotoElectronicoPersistentManager.instance().deleteObject(candidato);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Candidato candidato) throws PersistentException {
		try {
			orm.VotoElectronicoPersistentManager.instance().getSession().refresh(candidato);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Candidato candidato) throws PersistentException {
		try {
			orm.VotoElectronicoPersistentManager.instance().getSession().evict(candidato);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Candidato loadCandidatoByCriteria(CandidatoCriteria candidatoCriteria) {
		Candidato[] candidatos = listCandidatoByCriteria(candidatoCriteria);
		if(candidatos == null || candidatos.length == 0) {
			return null;
		}
		return candidatos[0];
	}
	
	public Candidato[] listCandidatoByCriteria(CandidatoCriteria candidatoCriteria) {
		return candidatoCriteria.listCandidato();
	}
}
